// FrogImageResizeDialog.h : Declaration of the CFrogImageLogoDialog

#pragma once

#include "resource.h"       // main symbols
#include <atlhost.h>
#include "FrogProgressReportDialog.h"
#include <gdiplus.h>
#include "Controls\ColorButton.h"

// CFrogImageLogoDialog

struct ImageLogoConfig
{
	// Font
	LOGFONTW logoFont;
	Gdiplus::Color fontColor;

	bool useBorder;
	Gdiplus::Color borderColor;

	bool useImage;
	wchar_t logoFile[MAX_PATH];

	bool putInFolder;
	wchar_t folder[MAX_PATH];

	wchar_t logoText[1024];

	int postion;

	ImageLogoConfig():
	fontColor(Gdiplus::Color::White),
		borderColor(Gdiplus::Color::OrangeRed),
		useImage(false),
		putInFolder(false),
		postion(0),
		useBorder(true)
	{	
		logoFile[0] = L'\0';
		folder[0] =  L'\0';
		logoText[0] = L'\0';

		logoFont.lfHeight = -24;
		logoFont.lfWeight = 700;
		logoFont.lfCharSet = 177;
		logoFont.lfOutPrecision = 1;
		logoFont.lfClipPrecision = 2;
		logoFont.lfQuality = 1;
		logoFont.lfPitchAndFamily = 34;
		wcscpy_s(logoFont.lfFaceName, LF_FACESIZE, L"Times new Roman");
	}

	bool SaveToRegistry()
	{	
		CRegKey key;
		long nError = key.Create(HKEY_CURRENT_USER, L"Software\\FilerFrog");

		if (nError == ERROR_SUCCESS)
		{
			if (key.SetBinaryValue(L"LastPutLogoData", this, sizeof(ImageLogoConfig)) == ERROR_SUCCESS)
			{
				return true;
			}
		}

		return false;
	}

	bool LoadFromRegistry()
	{
		CRegKey key;
		long nError = key.Open(HKEY_CURRENT_USER, L"Software\\FilerFrog", KEY_READ);

		if (nError == ERROR_SUCCESS)
		{
			ULONG pnBytes = sizeof(ImageLogoConfig);

			if (key.QueryBinaryValue(L"LastPutLogoData", this, &pnBytes) == ERROR_SUCCESS)
			{
				return true;
			}
		}

		return false;
	}
};

class CFrogImageLogoDialog: public CFrogProgressReportDialog<CFrogImageLogoDialog>,
	public CWinDataExchange<CFrogImageLogoDialog>
{
public:

	enum { IDD = IDD_DIALOG_IMAGE_LOGO };

	CFrogImageLogoDialog(HICON hIcon);	

	BEGIN_MSG_MAP(CFrogImageLogoDialog)
		MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
		COMMAND_HANDLER(IDOK, BN_CLICKED, OnClickedOk)
		COMMAND_HANDLER(IDCANCEL, BN_CLICKED, OnClickedCancel)
		COMMAND_ID_HANDLER(IDC_BUTTON_FONT, OnButtonFont)
		COMMAND_HANDLER(IDC_BUTTON_BROWSE, BN_CLICKED, OnClickedBrowse)
		COMMAND_HANDLER(IDC_CHECK_PUT_IN_FOLDER, BN_CLICKED, OnCheckPutInFolderBnClicked)
		COMMAND_HANDLER(IDC_CHECK_ADD_BORDER, BN_CLICKED, OnCheckAddBorder)		
		COMMAND_HANDLER(IDC_RADIO_FILE, BN_CLICKED, OnClickedRadioLogo)
		COMMAND_HANDLER(IDC_RADIO_TEXT, BN_CLICKED, OnClickedRadioLogo)
		// FrogBaseDialog Inherited
		CHAIN_MSG_MAP(CFrogProgressReportDialog)
		REFLECT_NOTIFICATIONS()
	END_MSG_MAP()

	BEGIN_DDX_MAP(CFrogImageLogoDialog)		
		DDX_TEXT(IDC_EDIT_LOGO, m_LogoImagePath)
		DDX_RADIO(IDC_RADIO1, m_Postion)
		DDX_TEXT(IDC_EDIT_FOLDER, m_Folder)
		DDX_TEXT(IDC_EDIT_LOGO_TEXT, m_LogoText)		
		DDX_CHECK(IDC_CHECK_PUT_IN_FOLDER, m_PutInFolder)
		DDX_CHECK(IDC_CHECK_ADD_BORDER, m_AddBorder)
	END_DDX_MAP()

	// Handler prototypes:
	//  LRESULT MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
	//  LRESULT CommandHandler(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled);
	//  LRESULT NotifyHandler(int idCtrl, LPNMHDR pnmh, BOOL& bHandled);

	LRESULT OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
	virtual void ExecuteCommand();

private:
	CString m_LogoImagePath;
	int m_Postion;
	CEdit m_EditFolder;
	CString m_Folder;
	CString m_LogoText;
	bool m_PutInFolder;
	bool m_AddBorder;
	CButton m_CheckBoxPutInFolder;
	CButton m_CheckBoxAddBorder;
	CStatic m_FontName;
	CButton m_RadioLogoFile;
	CButton m_RadioLogoText;

	CColorButton m_ColorBtn1;

	// Config
	ImageLogoConfig m_ImageLogoConfig;

	void GetSelectedFont(CStatic& fontName);
	void UpdateFontLabel(CStatic& fontName, const LOGFONTW& font);

	LRESULT OnClickedOk(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled);
	LRESULT OnClickedBrowse(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled);

	LRESULT OnCheckPutInFolderBnClicked(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled);	
	LRESULT OnCheckAddBorder(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled);		

	LRESULT OnButtonFont(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled);
	LRESULT OnClickedRadioLogo(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled);		

	void EnableDisableButtons();
};